<?php
/**
 * Created by PhpStorm.
 * User: hanbin
 * Date: 17/4/11
 * Time: 下午3:55
 */

namespace App\Http\Controllers\Auth;


use App\Http\Controllers\BaseController;
use App\Logic\MessageLogic;
use Validator;
use Illuminate\Http\Request;

/**
 * 消息
 *
 * Class MessageController
 * @package App\Http\Controllers\Auth
 */
class MessageController extends BaseController
{
    public function __construct()
    {
        $this->setToken(true);
        parent::__construct();
    }

    /**
     * 消息大类列表
     */
    public function typeList()
    {
        return MessageLogic::typeList($this->userId);
    }

    /**
     * 消息列表
     *
     * @param Request $request
     * @return array
     */
    public function msgList(Request $request)
    {
        $params = $request->all();
        $rule = [
            'type' => 'required|string',
            'pagesize' => 'required|int',
            'last_id' => 'required|int',
        ];
        $message = [
            'type.required' => '类型不能为空',
            'pagesize.required' => '每页个数不能为空',
            'last_id.required' => '页码不能为空',
        ];
        $validator = Validator::make($params, $rule, $message);
        $errors = $validator->errors()->all();
        if (!empty($errors) && !$validator->passes()) {
            return $this->error($errors[0], 206);
        }
        return MessageLogic::msgList($this->userId, $params);
    }
}